<?php if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=""){?>
<div class="col-md-8">
<div class="main-content" id="main-content">
		<div class="sub-content">
			<div class="top-header">
				<h1>Sell Offer Info</h1>
			</div>
			<div class="top-links">
				<ul class="form-progress-bar">
				    <?if(isset($_GET['product_id']) && $_GET['product_id']!=""){?>
					    <li class="active-menu step-no"><a href="<? echo $this->Url('products')?>/add-product?product_id=<? echo $_GET['product_id'];?>"><span>1</span></a></li>
						<li class="indicator active-menu"><span></span></li>
						<li class="active-menu step-no"><a  href="<? echo $this->Url('products')?>/add-product-next?product_id=<? echo $_GET['product_id'];?>"><span>2</span></a></li>
					<?}else{?>
						<li class="active-menu step-no"><a href="<? echo $this->Url('products')?>/add-product"><span>1</span></a></li>
						<li class="indicator active-menu"><span></span></li>
						<li class="active-menu step-no"><a  href="<? echo $this->Url('products')?>/add-product-next"><span>2</span></a></li>
					<?}?>
					<li class="indicator"><span></span></li>
					<li  class="active-menu step-no"><span>3</span></li>
				</ul>
			</div>
			<div class="col-md-12">
				<form id="forms" method="post" class="form-horizontal" role="form">
					
						<div class="form-group">
								<label class="control-label col-sm-3">Selling</label>
								<div class="col-sm-9">
								<div class="select_6">
									<select id="selling" name="selling" class="form-control">
									    <option value="" >Select</option>
										<? if(isset($_SESSION['products']['selling']) && $_SESSION['products']['selling']=='Wholesale'){?>
											<option value="Wholesale" selected="selected" >Wholesale</option>
											<option value="Partly" >Partly</option>											
										<?}else if($_SESSION['products']['selling']=='Partly'){?>
											<option value="Wholesale">Wholesale</option>
											<option value="Partly" selected="selected">Partly</option>	
										<?}else if(isset($this->productsDeatils->saleing) && $this->productsDeatils->saleing=='Wholesale'){?>
											<option value="Wholesale" selected="selected">Wholesale</option>
											<option value="Partly" >Partly</option>	
										<?}else if(isset($this->productsDeatils->saleing) && $this->productsDeatils->saleing=='Partly'){?>
											<option value="Wholesale">Wholesale</option>
											<option value="Partly" selected="selected">Partly</option>	
										<?}else{?>
											<option value="Wholesale" >Wholesale</option>
											<option value="Partly" >Partly</option>											
										<?}?>
									</select>
								</div></div><span style="color:red" id="errorselling"></span>
						</div>
						<div class="form-group">
							
								<label class="control-label col-sm-3">Qty</label>
								<div class="col-sm-3">
								<? if(isset($_SESSION['products']['qty']) && $_SESSION['products']['qty']!=""){?>
									<input type="text" id="qty" name="qty" class="form-control" value="<? echo $_SESSION['products']['qty'];?>" placeholder="eg 1000" onBlur="Javascript:validatePackaging();" />
								<?}else if(isset($this->productsDeatils->quntity)){?>
										<input type="text" id="qty" name="qty" class="form-control" value="<? echo $this->productsDeatils->quntity;?>" placeholder="eg 1000" onBlur="Javascript:validatePackaging();" />
								<?}else{?>
									<input type="text" id="qty" name="qty" class="form-control" value="" placeholder="eg 1000" onBlur="Javascript:validatePackaging();" />
								<?}?>						
								</div>
							
								<label class="control-label col-sm-3">Units</label>
								<div class="col-sm-3">
								<? if(isset($_SESSION['products']['units']) && $_SESSION['products']['units']!=""){?>
									<input type="text" id="units" name="units" class="form-control" value="<? echo $_SESSION['products']['units'];?>" placeholder="eg Kg, Ltr" onBlur="Javascript:checkUnits();" />
								<?}else if(isset($this->productsDeatils->unites)){?>
										<input type="text" id="units" class="form-control" value="<? echo $this->productsDeatils->unites;?>" name="units" placeholder="eg Kg, Ltr" onBlur="Javascript:checkUnits();" />
								<?}else{?>
									<input type="text" id="units" name="units" class="form-control" value="" placeholder="eg Kg, Ltr" onBlur="Javascript:checkUnits();" />
								<?}?>	
							</div><span style="color:red" id="errorquantity"></span><span style="color:red; margin-left:190px;" id="errorunits"></span>
						</div>
						<div class=" form-group">							
								<label class="control-label col-sm-3">Year of Manufacture</label>
								<div class="col-sm-9">
								<? if(isset($_SESSION['products']['year']) && $_SESSION['products']['year']!=""){?>
									<input type="text" id="year"  name="year" class="form-control" value="<? echo $_SESSION['products']['year'];?>" placeholder="year" />
								<?}else if(isset($this->productsDeatils->year_of_manufacture)){?>
									<input type="text" id="year"  name="year" class="form-control" value="<? echo $this->productsDeatils->year_of_manufacture;?>" placeholder="year" />
								<?}else{?>
									<input type="text" id="year"  name="year" class="form-control" value="" placeholder="year" />
								<?}?>							
							</div><span style="color:red" id="erroryomanufavcture"></span>
						</div>
						<div class=" form-group">
							
								<label class="control-label col-sm-3">Packing</label>
								<div class="col-sm-3">
								<? if(isset($_SESSION['products']['packing']) && $_SESSION['products']['packing']!=""){?>
									<input type="text" id="packing" class="form-control" value="<? echo $_SESSION['products']['packing'];?>" name="packing" placeholder="eg 200" onBlur="Javascript:validatePackaging();" />
								<?}else if(isset($this->productsDeatils->package)){?>
									<input type="text" id="packing" class="form-control" value="<? echo $this->productsDeatils->package;?>" name="packing" placeholder="eg 200" onBlur="Javascript:validatePackaging();"  />
								<?}else{?>
									<input type="text" id="packing" class="form-control" value="" name="packing" placeholder="eg 200" onBlur="Javascript:validatePackaging();"  />
								<?}?>		
								</div>
								<label class="control-label col-sm-3">per</label>
								<div class="col-sm-3">
								<? if(isset($_SESSION['products']['per']) && $_SESSION['products']['per']!=""){?>
									<input type="text" id="per" name="per" class="form-control" readonly="readonly" value="<? echo $_SESSION['products']['per'];?>" placeholder="eg Drum, Bag, Tote"  />
								<?}else if(isset($this->productsDeatils->per)){?>
									<input type="text" id="per" name="per" class="form-control" readonly="readonly" value="<? echo $this->productsDeatils->per;?>" placeholder="eg Drum, Bag, Tote"  />
								<?}else{?>
									<input type="text" id="per" name="per" class="form-control" readonly="readonly" value="" placeholder="eg Drum, Bag, Tote" />
								<?}?>	</div>							
							
						</div><span style="color:red" id="errorpacking">&nbsp;&nbsp;</span><span style="color:red; margin-left:222px;" id="errorper" ></span>
						<div class="form-group">
								<label class="control-label col-sm-3">Type</label>
								<div class="col-sm-9">
								<div class="select_6">
									<select id="type" name="type" onchange="hideMiniprice()" class="form-control">
									    <option value="" >Select</option>
										<? if(isset($_SESSION['products']['type']) && $_SESSION['products']['type']=='bid'){?>
											<option value="buy" >Sell</option>
											<option value="bid" selected="selected">Sell or Bid</option>											
										<?}else if($_SESSION['products']['type']=='buy'){?>
											<option value="buy"  selected="selected">Sell</option>
											<option value="bid">Sell or Bid</option>											
										<?}else if(isset($this->productsDeatils->type) && $this->productsDeatils->type=='bid'){?>
											<option value="buy" >Sell</option>
											<option value="bid" selected="selected">Sell or Bid</option>											
										<?}else if($this->productsDeatils->type=='buy'){?>
											<option value="buy" selected="selected">Sell</option>
											<option value="bid" >Sell or Bid</option>											
										<?}else{?>
											<option value="buy" >Sell</option>
											<option value="bid" >Sell or Bid</option>											
										<?}?>
									</select>
								</div></div>
						</div><span style="color:red" id="errortype"></span>
						<div class=" form-group">							
								<label class="control-label col-sm-3">Suggested Price</label>
								<div class="col-sm-3">
									<span class="form-control">
										<? if(isset($_SESSION['countryprice']) && $_SESSION['countryprice']){
											echo strtoupper($_SESSION['countryprice']);
										}else{ 
											echo 'INR';
										}?>
									</span>
								</div>&nbsp;&nbsp;<div class="col-sm-3">
								<? if(isset($_SESSION['products']['tsh']) && $_SESSION['products']['tsh']!=""){?>
									<input type="text" id="tsh" name="tsh" class="form-control" value="<? echo $_SESSION['products']['tsh'];?>" placeholder="eg 600" />
								<?}else if(isset($this->productsDeatils->suggested_price)){?>
									<input type="text" id="tsh" name="tsh" class="form-control" value="<? echo $this->productsDeatils->suggested_price;?>" placeholder="eg 600" />
								<?}else{?>
									<input type="text" id="tsh" name="tsh" class="form-control" value="" placeholder="eg 600" />
								<?}?>									
								</div>
							
						</div><span style="color:red" id="errorsprice"></span>
						<div class=" form-group" id="hidminprice" style="display:none;">
							
								<label class="control-label col-sm-3">Min Price</label>
								<div class="col-sm-3">
									<span class="form-control">
										<? if(isset($_SESSION['countryprice']) && $_SESSION['countryprice']){
											echo strtoupper($_SESSION['countryprice']);
										}else{ 
											echo 'INR';
										}?>
									</span>
								</div>&nbsp;&nbsp;<div class="col-sm-3">
								<? if(isset($_SESSION['products']['tshm']) && $_SESSION['products']['tshm']!=""){?>
									<input type="text" id="tshm" name="tshm" class="form-control" value="<? echo $_SESSION['products']['tshm'];?>" placeholder="eg 500"  />
								<?}else if(isset($this->productsDeatils->min_price)){?>
									<input type="text" id="tshm" class="form-control" value="<? echo $this->productsDeatils->min_price;?>" name="tshm" placeholder="eg 500" />
								<?}else{?>
									<input type="text" id="tshm" class="form-control" value="" name="tshm" placeholder="eg 500" />
								<?}?>									
								</div>
							
						</div><span style="color:red" id="errormprice"></span>			
							<input type="hidden" id="user_currency" name="user_currency" value="<? if(isset($_SESSION['countryprice']) && $_SESSION['countryprice']){echo strtoupper($_SESSION['countryprice']);}else{ echo 'INR';}?>">										
						<? if(isset($this->productsDeatils->user_id) && $this->productsDeatils->user_id!=$_SESSION['user']['user_id']){?>
						<div class="sub_off">
							
								<label class="control-label col-sm-3">Status</label>
								<div class="col-sm-9">
								<div class="select_6">
									<select id="p_status" name="p_status" class="form-control">	
										<? if(isset($_SESSION['products']['p_status']) && $_SESSION['products']['p_status']=='0'){?>
											<option value="0" selected="selected">Pending</option>
											<option value="1">Activate</option>
											<option value="2">Inactivate</option>
										<? } else if($_SESSION['products']['p_status']=='1'){?>
											<option value="0">Pending</option>
											<option value="1" selected="selected">Activate</option>
											<option value="2">Inactivate</option>
										<?} else if($_SESSION['products']['p_status']=='2'){?>
											<option value="0">Pending</option>
											<option value="1">Activate</option>
											<option value="2" selected="selected">Inactivate</option>
										<?} else if(isset($productsDeatils->p_status) && $productsDeatils->p_status=='0'){?>
											<option value="0" selected="selected">Pending</option>
											<option value="1">Activate</option>
											<option value="2">Inactivate</option>
										<?} else if($productsDeatils->p_status=='1'){?>
											<option value="0" >Pending</option>
											<option value="1" selected="selected">Activate</option>
											<option value="2">Inactivate</option>
										<?} else if($productsDeatils->p_status=='2'){?>
											<option value="0">Pending</option>
											<option value="1">Activate</option>
											<option value="2" selected="selected">Inactivate</option>
										<?} else {?>
											<option value="0">Pending</option>
											<option value="1">Activate</option>
											<option value="2">Inactivate</option>
										<?}?>
									</select>
								</div></div>
							
						</div>
						<?php } else if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']!="superadmin"){ ?>
							<? if(isset($this->productsDeatils->p_status) && $this->productsDeatils->p_status!=''){?>
								<div class="sub_off form-group">
									
										<label class="control-label col-sm-3">Status</label>
										<div class="col-sm-9">
										<input type="hidden" id="p_status" name="p_status" value="<? echo $this->productsDeatils->p_status;?>">
										<? if($this->productsDeatils->p_status==0){?>
											<input type="text" readonly="readonly" value="Pending" class="form-control">
										<?} else if($this->productsDeatils->p_status==1){?>
											<input type="text" readonly="readonly" value="Activate" class="form-control">
										<?} else if($this->productsDeatils->p_status==2){?>
											<input type="text" readonly="readonly" value="Inactivate" class="form-control">
										<?}?>
									</div>
								</div>
							<?}?>
						<? }else {?>
						<div class="sub_off form-group">
							
								<label class="control-label col-sm-3">Status</label>
								<div class="col-sm-9">
								<div class="select_6">
									<select id="p_status" name="p_status" class="form-control">	
										<? if(isset($_SESSION['products']['p_status']) && $_SESSION['products']['p_status']=='0'){?>
											<option value="0" selected="selected">Pending</option>
											<option value="1">Active</option>
											<option value="2">InActive</option>
										<? } else if($_SESSION['products']['p_status']=='1'){?>
											<option value="0">Pending</option>
											<option value="1" selected="selected">Active</option>
											<option value="2">InActive</option>
										<?} else if($_SESSION['products']['p_status']=='2'){?>
											<option value="0">Pending</option>
											<option value="1">Active</option>
											<option value="2" selected="selected">InActive</option>
										<?} else if(isset($productsDeatils->p_status) && $productsDeatils->p_status=='0'){?>
											<option value="0" selected="selected">Pending</option>
											<option value="1">Active</option>
											<option value="2">InActive</option>
										<?} else if($productsDeatils->p_status=='1'){?>
											<option value="0" >Pending</option>
											<option value="1" selected="selected">Active</option>
											<option value="2">InActive</option>
										<?} else if($productsDeatils->p_status=='2'){?>
											<option value="0">Pending</option>
											<option value="1">Active</option>
											<option value="2" selected="selected">InActive</option>
										<?} else {?>
											<option value="0">Pending</option>
											<option value="1">Active</option>
											<option value="2">InActive</option>
										<?}?>
									</select>
								</div>
							</div>
						</div>
						<?php } ?>
						<input type="hidden" id="hid_product_id" name="hid_product_id" value="<? if(isset($this->productsDeatils->product_id)){ echo $this->productsDeatils->product_id;}?>"/>
						<input type="hidden" id="hid_product_user_id" name="hid_product_user_id" value="<? if(isset($this->productsDeatils->user_id)){ echo $this->productsDeatils->user_id;}?>">
						<input type="hidden" id="pak_status" name="pak_status" value="0" />
						<div class="form-group">
						<div class="col-sm-3">&nbsp;</div>
						<div class="col-sm-9">
						<a href="javascript:void(0)" class="btn btn-danger" onclick="return submitValues()" role="button">Continue</a></div>
						</div>
					
				</form>
			</div>                
		</div>
</div></div>
<script>
$( document ).ready(function() {
	hideMiniprice();
});
	function hideMiniprice(){
		var type=$('#type').val();
		if( type == 'bid' ){
			$("#hidminprice").show();
		}else{
			$('#errormprice').html('');
			$("#hidminprice").hide();
		}
	}
	function checkUnits()
	{
		if( $('#units').val() != "" )
		{
			$('#errorunits').html('');	
		}
	}
	function checkQuantity()
	{
		var quantity=$('#qty').val();
	
		if( $('#errorquantity').html() != "" )
		{
			$('#errorquantity').html('');
		}
		
	}


	function validatePackaging()
	{
		document.getElementById('per').value='';
		var quantity=$('#qty').val();
		var units=$('#units').val();
		var packig=$('#packing').val();
		var per=$('#per').val();
		
		var flag = true;
		
		if( quantity == "" )
		{
			$('#errorquantity').html('*Quantity is required');	
			flag = false;
		}
		else
		{
			$('#errorquantity').html('');
			if( quantity == 0 )
			{
				$('#errorquantity').html('*Quantity cannot be 0.');	
				flag = false;
			}
			else
			{
				$('#errorquantity').html('');
			}
		}
		if( units == "" )
		{
			$('#errorunits').html('*Units is required');	
			flag = false;
		}
		else
		{
			$('#errorunits').html('');
		}
		if( packig == "" )
		{
		   $('#errorpacking').html('*Packing is required');	
			flag = false;
		}
		else
		{
			$('#errorpacking').html('');
			if( packig == 0 )
			{
				$('#errorpacking').html('*Packing cannot be 0.');	
				flag = false;
			}
			else
			{
				$('#errorpacking').html('');
			}
		}
		if( (quantity != "") && (packig != "") && (quantity != 0) && (packig != 0) )
		{
			if( (quantity % packig) != 0 )
			{
				$('#errorquantity').html('*Enter valid quantity.');
				flag = false;				
			}
			else
			{
				$('#errorquantity').html('');
				$('#per').val( $('#qty').val() / $('#packing').val() );
				$("#pak_status").val(1);
				flag = true;
			}
		}
		
		return flag;
	}

	function submitValues(){
	    var flag=true;	
		var letters = /^[a-zA-Z ]*$/; 
		var numbers = /^[0-9]+$/;
		var selling=$('#selling').val();
		var quantity=$('#qty').val();
		var units=$('#units').val();
		var year=$('#year').val();
		var packig=$('#packing').val();
		var per=$('#per').val();
		var sprice=$('#tsh').val();
		var minprice=$('#tshm').val();
		var type=$('#type').val();
		if(selling==""){
		   $('#errorselling').html('*selling is required');	
		   flag=false;
		}else{
			$('#errorselling').html('');
		}
		if(quantity==""){
		   $('#errorquantity').html('*Quantity is required');	
		   flag=false;
		}else{
			$('#errorquantity').html('');
		}
		if(units==""){
			$('#errorunits').html('*Units is required');	
			flag=false;
		}else{
			$('#errorunits').html('');
		}
		if(year==""){
			$('#erroryomanufavcture').html('*Year of manufacture is required');
			flag=false;
		}else{
			$('#erroryomanufavcture').html('');
		}
		if(packig==""){
			$('#errorpacking').html('*Packing is required');
			flag=false;
		}else{
			$('#errorpacking').html('');
		}
		if(type==""){
		  $('#errortype').html('*Type is required');
		  flag=false;
		}else{
		   $('#errortype').html('');
		}
		if(sprice==""){
		  $('#errorsprice').html('*Suggested price is required');
		  flag=false;
		}else if(isNaN(sprice)){
				$('#errorsprice').html('*Numbers only');
			  flag=false;
		}else{
		   $('#errorsprice').html('');
		}
		if(type == 'bid'){
			if(minprice==""){
			  $('#errormprice').html('*Minimum price is required');
			  flag=false;
			}else if(isNaN(minprice)){
				$('#errormprice').html('*Numbers only');
			  flag=false;
			}else{
			   $('#errormprice').html('');
			}
		}
		 validatePackaging();
		if(parseInt($("#pak_status").val())!='1'){
		return false;
		
		}
		if(flag==false){ 
			return false;
		}else{		
		  $("#forms").submit();
		}
	}
</script>
<?php }else{?>
<script>
	window.location='<? echo $this->Url('home')?>';
</script>
<?php }?>